support uint64
for case statement operands
#820
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Allow
uint64
values to be used ascase
-statement operands and fixmultiple compiler crashes with
uint
of
-branch labels outside theint64
range. Previously, trying to use auint64
value with casestatements resulted in a "selector must be of an ordinal type" error.
uint64
values can now be used ascase
-statement operands (outsideof objects)
of
-branches don't crash the compilerwhen the range of the element value crosses
high(int64)
..
ranges inof
-branches don'tcrash the compiler when the lower bound is less-than-or-equal to,
and the upper bound greater than
high(int64)
high(int64)
are not treated as-1 - high(uint64) - value
anymore
Details
uint64
being disallowed ascase
-statement operands seems to havebeen a leftover from when
uint64
was not considered an ordinal type.Since it is considered an ordinal type now, not allowing it there is
inconsistent.
The compiler crashes were all caused by signed integer overflow
defects. All integer values are stored as
BiggestInt
(signed) inPNode
, even unsigned values. Prior to working with them, they have tobe either casted to an unsigned integer (in case the node represents
an unsigned value) or turned into an
Int128
value viagetOrdValue
/getInt
(both which take care of properly reinterpreting the value).This was missing in
toTreeSet
, which is called when removingduplicate elements from set literals used as
of
-branch labels.Instead of turning the sets' lower bound (
firstOrd
) into a signedinteger, the value is now kept as an
Int128
, fixing the overflowdefect.
The other problems where with the C and JavaScript code generators,
both which were using the nodes
intVal
directly when iterating overnkRange
s -- they now useInt128
values. In order to not havingto create a temporary
PNode
, the integer-literal rendering logicfor both code generators is moved to standalone procedures that take
an
Int128
value directly (which for the JavaScript backend fixeslarge unsigned values being inverted).
Instead of inferring the integer type from the node kind,
cgen
nowrequires all integer literals to be typed, which is preparation for the
code-generator IR.
When using the VM backend,
of
-branches with ranges crossinghigh(int64)
still don't work correctly, as the VM uses signedintegers for the comparisons. Fixing this requires a larger rethinking
of the VM's case statement support, and it is thus left as is for now.